package com.yanqu.road.server.cmd.activity.seacraft.pirateriot;

import com.yanqu.road.pb.activity.SeacraftPirateRiotProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.seacraft.SeacraftPirateRiotModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SEACRAFT_PIRATE_RIOT_GET_CHAPTER, desc = "获取关卡数据")
public class SeacraftPirateRiotGetChapterCmd extends AbstractCommand {

    private int chapterId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SeacraftPirateRiotProto.SeacraftPirateRiotGetChapterReqMsg reqMsg = SeacraftPirateRiotProto.SeacraftPirateRiotGetChapterReqMsg.parseFrom(packet.getBytes());
        chapterId = reqMsg.getChapterId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SeacraftPirateRiotModule.class).getChapterData(chapterId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            SeacraftPirateRiotProto.SeacraftPirateRiotGetChapterRespMsg.Builder builder = SeacraftPirateRiotProto.SeacraftPirateRiotGetChapterRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SEACRAFT_PIRATE_RIOT_GET_CHAPTER, builder);
        }
    }
}
